- Overview
- UI Automation
- UI-ANA-016 - Pull Open Browser URL
- UI-ANA-017 - ContinueOnError True
- UI-ANA-018 - List OCR/Image Activities
- UI-DBP-006 - Container Usage
- UI-DBP-013 - Excel Automation Misuse
- UI-DBP-030 - Forbidden Variables Usage In Selectors
- ST-DBP-021 - Hardcoded Timeout
- UI-PRR-001 - Simulate Click
- UI-PRR-002 - Simulate Type
- UI-PRR-003 - Open Application Misuse
- UI-PRR-004 - Hardcoded Delays
- UI-REL-001 - Large Idx in Selectors
- UI-SEC-004 - Selector Email Data
- UI-SEC-010 - App/Url Restrictions
- UI-USG-011 - Non Allowed Attributes
- SY-USG-013 - Private File Invoke
- SY-USG-014 - Incorrect Execution Template Placeholders
- Applications and technologies automated with UI Automation
- UiPath Browser Migration Tool
- Computer Vision Recorder
- Click
- Hover
- Type Secure Text
- Send Hotkey
- Type Into
- Check
- Select Item
- Select Multiple Items
- Get Text
- Set Text
- Activate
- Highlight
- Set Focus
- Anchor Base
- Context Aware Anchor
- Find Relative Element
- Indicate On Screen
- Element Exists
- Find Element
- Wait Element Vanish
- Find Children
- Get Ancestor
- Element Scope
- Get Attribute
- Set Clipping Region
- Get Position
- Take Screenshot
- Wait Attribute
- On Element Appear
- On Element Vanish
- Click Text
- Hover Text
- Find Text Position
- Get Full Text
- Get Visible Text
- Extract Structured Data
- Text Exists
- Click OCR Text
- Hover OCR Text
- Get OCR Text
- Find OCR Text Position
- Microsoft OCR
- Microsoft Project Oxford Online OCR
- Microsoft Azure Computer Vision OCR
- Tesseract OCR
- Google Cloud Vision OCR
- OCR Text Exists
- Click Image
- Hover Image
- Find Image Matches
- Image Exists
- Find Image
- Wait Image Vanish
- On Image Appear
- On Image Vanish
- Load Image
- Save Image
- Attach Browser
- Close Tab
- Go Back
- Go Forward
- Go Home
- Inject JS Script
- Navigate To
- Open Browser
- Refresh Browser
- Set Web Attribute
- Attach Window
- Close Window
- Get Active Window
- Hide Window
- Maximize Window
- Minimize Window
- Move Window
- Restore Window
- Show Window
- Export UI Tree
- Invoke ActiveX Method
- Inject .NET Code
- Click Trigger
- Key Press Trigger
- Click Image Trigger
- System Trigger
- Hotkey Trigger
- Mouse Trigger
- Get Event Info
- Monitor Events
- Get Source Element
- Replay User Event
- Block User Input
- Use Foreground
- Element Attribute Change Trigger
- Element State Change Trigger
- Callout
- Copy Selected Text
- Get From Clipboard
- Set To Clipboard
- Close Application
- Open Application
- Start Process
- Get Password
- Tooltip
- Click Picture on Screen
- Click Toolbar Button
- Read Statusbar
- Select Dates in Calendar
- Select Menu Item
- Expand Tree
- Call Transaction
- SAP Logon
- SAP Login
- Table Cell Scope
- SAP Session Attributes Change Trigger
- Expand ALV Tree
- Expand ALV Hierarchical Table
- Use Application/Browser
- Check App State
- Check/Uncheck
- Click
- Extract Table Data
- Get Text
- Get URL
- Go to URL
- Highlight
- Hover
- Keyboard Shortcuts
- Navigate Browser
- Select Item
- Take Screenshot
- Type Into
- Get Attribute
- Get Browser Data
- Set Browser Data
- Mouse Scroll
- Inject Js Script
- Drag and Drop
- For Each UI Element
- Application Event Trigger
- Click Event Trigger
- Keypress Event Trigger
- Set Text
- Check Element
- Fill Form
- Perform browser search and retrieve results using UI Automation APIs
- Web Browsing
- Find Images
- Click Images
- Trigger and Monitor Events
- Create and Override Files
- HTML Pages: Extract and Manipulate Information
- Window Manipulation
- Automated List Selection
- Find and Manipulate Window Elements
- Manage Text Automation
- Load and Process Images
- Manage Mouse Activated Actions
- Automate Application Runtime
- Automated Run of a Local Application
- Browser Navigation
- Web Automation
- Trigger Scope Example
- Computer Vision Local Server
- Mobile Automation
- Release notes
- Project compatibility
- Get Log Types
- Get Logs
- Get Page Source
- Get Device Orientation
- Get Session Identifier
- Install App
- Manage Current App
- Manage Other App
- Open DeepLink
- Open URL
- Mobile Device Connection
- Positional Swipe
- Press Hardware Button
- Set Device Orientation
- Take Screenshot
- Take Screenshot Part
- Element Exists
- Execute Command
- Get Attribute
- Get Selected Item
- Get Text
- Set Selected Item
- Set Text
- Swipe
- Tap
- Type Text
- Draw Pattern
- Terminal
Inject .NET Code
UiPath.Core.Activities.InjectDotNetCode
Injects .NET code into the main UI thread of the target application. Intended for usage with .NET UI applications that do not expose traditional automation technologies or cannot be correctly targeted by traditional means.
Common
-
ContinueOnError - Specifies if the automation should continue even when the activity throws an error. This field only supports Boolean values (True, False). The default value is False. As a result, if the field is blank and an error is thrown, the execution of the project stops. If the value is set to True, the execution of the project continues regardless of any error.
Note: If this activity is included in Try Catch and the value of the ContinueOnError property is True, no error is caught when the project is executed. - DisplayName - The display name of the activity.
Input
- Assembly - The full path to the Compiled .NET assembly that you want to inject. This field supports only strings and
String
variables. -
Method Name - The name of the method you want to execute. Only public static methods are supported.
Note: A type cannot contain multiple methods with the same name. If this is the case, an error is thrown at runtime. - Target.ClippingRegion - Defines the clipping rectangle, in pixels, relative to the UiElement, in the following directions: left, top, right, bottom. It supports both positive and negative numbers.
- Target.Element - Use the UiElement variable returned by another activity. This property cannot be used alongside the Selector property. This field supports only UiElement variables.
- Target.Selector - Text property used to find a particular UI element when the activity is executed. It is actually a XML fragment specifying attributes of the GUI element you are looking for and of some of its parents.
- Target.TimeoutMS - Specifies the amount of time (in milliseconds) to wait for the activity to run before the
SelectorNotFoundException
error is thrown. The default value is 30000 milliseconds (30 seconds). -
Target.WaitForReady - Before performing the actions, wait for the target to become ready. The following options are available:
- None - Does not wait for anything except the target UI element to exist before executing the action. For example, you can use this option if you want to retrieve just text from a web page or click a particular button, without having to wait for all UI elements to load. Note that this may have unwanted consequences if the button relies on elements which are not yet loaded, such as scripts.
-
Interactive/Complete - Waits all of the UI elements in the target app to exist before actually executing the action.
To assess if an application is in the Interactive or Complete state, the following tags are verified:
- Desktop applications - A
wm_null
message is sent to check the existence of the<wnd>
,<ctrl>
,<java>
, or<uia>
tags. If they exist, the activity is executed. - Web applications:
- Internet Explorer - The
<webctrl>
tag is used to check if the Ready state of the HTML document is set to Complete. Additionally, the Busy state has to be set to "False". - Others - The
<webctrl>
tag is used to check if the Ready state of the HTML document is Complete.
- SAP applications - First the presence of the
<wnd>
tag verified, after which a SAP specific API is used to detect if the session is busy or not.
- TypeName - The name of the public class that contains the executing method. This field supports only strings and
String
variables.
Misc
- Private - If selected, the values of variables and arguments are no longer logged at Verbose level.
Output
- Result - The result of the invoked method, stored in an
Object
variable. This field supports onlyObject
variables.
The Inject .NET Code activity injects code only in the default AppDomain.
Some applications are structured in a way that the elements you may require to access or manipulate are not located within the default AppDomain, so injecting code in the default AppDomain is not enough. So, if the UI elements you want to indicate are located in another AppDomain, they are not available to the injected code.
To fix this, you have to modify the injection process to target the precise AppDomain containing the UI elements. More exactly, you need to inject code from the function that is executed in the default AppDomain into either all the non-default AppDomains or the specific non-default AppDomain containing the UI elements you want to indicate.
MarshalByRefObject
, containing the function you want to
execute in non-default
AppDomains:public class CrossAppDomainRunner : MarshalByRefObject
{
public void Execute(IntPtr controlHandle)
{
// Implementation of the method that will be executed in the target AppDomain
Trace.WriteLine("Sunt in " + AppDomain.CurrentDomain.FriendlyName);
Control foundControl = null;
try
{
foundControl = Control.FromHandle(controlHandle);
}
catch (Exception controlException)
{
int lastWin32Error = Marshal.GetLastWin32Error();
Trace.WriteLine($"+++++ An exception occurred while getting the control from handle {controlHandle}. The message is: {controlException.Message}, Win32 Error: {lastWin32Error}");
}
if (foundControl != null)
{
Trace.WriteLine($"+++++ Found control {foundControl.Name} from handle {controlHandle}");
}
else
{
int lastWin32Error = Marshal.GetLastWin32Error();
Trace.WriteLine($"+++++ Control NOT found based on handle {controlHandle}, Win32 Error: {lastWin32Error}");
}
}
}
public class CrossAppDomainRunner : MarshalByRefObject
{
public void Execute(IntPtr controlHandle)
{
// Implementation of the method that will be executed in the target AppDomain
Trace.WriteLine("Sunt in " + AppDomain.CurrentDomain.FriendlyName);
Control foundControl = null;
try
{
foundControl = Control.FromHandle(controlHandle);
}
catch (Exception controlException)
{
int lastWin32Error = Marshal.GetLastWin32Error();
Trace.WriteLine($"+++++ An exception occurred while getting the control from handle {controlHandle}. The message is: {controlException.Message}, Win32 Error: {lastWin32Error}");
}
if (foundControl != null)
{
Trace.WriteLine($"+++++ Found control {foundControl.Name} from handle {controlHandle}");
}
else
{
int lastWin32Error = Marshal.GetLastWin32Error();
Trace.WriteLine($"+++++ Control NOT found based on handle {controlHandle}, Win32 Error: {lastWin32Error}");
}
}
}
Execute
function that receives an
IntPtr
parameter. This parameter contains the value of the
control you are trying to find. In this example, you need to pass only an
IntPtr
parameter, but in your particular situation, you can add
as many parameters as you want.
ICorRuntimeHost
interface from mscoree
. To do
so, you need to declare that interface:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
namespace mscoree
{
[CompilerGenerated]
[Guid("CB2F6722-AB3A-11D2-9C40-00C04FA30A3E")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[TypeIdentifier]
[ComImport]
[CLSCompliant(false)]
public interface ICorRuntimeHost
{
void _VtblGap1_11();
void EnumDomains(out IntPtr enumHandle);
void NextDomain([In] IntPtr enumHandle, [MarshalAs(UnmanagedType.IUnknown)] out object appDomain);
void CloseEnum([In] IntPtr enumHandle);
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
namespace mscoree
{
[CompilerGenerated]
[Guid("CB2F6722-AB3A-11D2-9C40-00C04FA30A3E")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[TypeIdentifier]
[ComImport]
[CLSCompliant(false)]
public interface ICorRuntimeHost
{
void _VtblGap1_11();
void EnumDomains(out IntPtr enumHandle);
void NextDomain([In] IntPtr enumHandle, [MarshalAs(UnmanagedType.IUnknown)] out object appDomain);
void CloseEnum([In] IntPtr enumHandle);
}
}
You need to declare a class containing native methods to initialise the Component Object Model (COM):
public static class NativeMethods
{
[DllImport("ole32.dll")]
public static extern int CoInitializeEx(IntPtr pvReserved, COINIT dwCoInit);
public enum COINIT : uint
{
/// Initializes the thread for multi-threaded object concurrency.
COINIT_MULTITHREADED = 0x0,
/// Initializes the thread for apartment-threaded object concurrency.
COINIT_APARTMENTTHREADED = 0x2,
// ...
}
}
public static class NativeMethods
{
[DllImport("ole32.dll")]
public static extern int CoInitializeEx(IntPtr pvReserved, COINIT dwCoInit);
public enum COINIT : uint
{
/// Initializes the thread for multi-threaded object concurrency.
COINIT_MULTITHREADED = 0x0,
/// Initializes the thread for apartment-threaded object concurrency.
COINIT_APARTMENTTHREADED = 0x2,
// ...
}
}
ICorRunttimeHost
object:
public static ICorRuntimeHost GetCorRuntimeHost()
{
return (ICorRuntimeHost)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("CB2F6723-AB3A-11D2-9C40-00C04FA30A3E")));
}
public static ICorRuntimeHost GetCorRuntimeHost()
{
return (ICorRuntimeHost)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("CB2F6723-AB3A-11D2-9C40-00C04FA30A3E")));
}
GetControlData
is executed by the Inject .NET
Code activity in the default AppDomain:
public static void GetControlData(Int64 controlHandle, out string response)
{
//initialising COM
NativeMethods.CoInitializeEx(IntPtr.Zero, NativeMethods.COINIT.COINIT_MULTITHREADED);
mscoree.ICorRuntimeHost host = null;
try
{
host = (ICorRuntimeHost)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("CB2F6723-AB3A-11D2-9C40-00C04FA30A3E")));
}
catch (COMException comEx)
{
Trace.WriteLine($"COMException: {comEx.Message}, HRESULT: {comEx.ErrorCode}");
}
catch (Exception ex)
{
// Handle other exceptions
Trace.WriteLine($"Exception: {ex.Message}");
}
IntPtr enumHandle = IntPtr.Zero;
try
{
//now that we have ICorRuntimeHost object we can use it to enumerate the other domains
host.EnumDomains(out enumHandle);
object domain = null;
host.NextDomain(enumHandle, out domain);
while (domain != null)
{
//for each appdomain obtained
AppDomain appDomain = (AppDomain)domain;
//appDomain.BaseDirectory; - you might want to copy your dll
//in the appDomain.BaseDirectory cause otherwise it might not find
//the assembly
ObjectHandle handle = appDomain.CreateInstance(
typeof(CrossAppDomainRunner).Assembly.FullName,
typeof(CrossAppDomainRunner).FullName);
// Unwrap to get the actual object
var runnerProxy = handle.Unwrap();
// Use reflection to call the Execute method
MethodInfo executeMethod = runnerProxy.GetType().GetMethod("Execute", new Type[] { typeof(IntPtr) });
//pass parameters as new object[]
executeMethod.Invoke(runnerProxy, new object[] { new IntPtr(controlHandle) });
//go to next appdomain
host.NextDomain(enumHandle, out domain);
if (domain == null)
break;
}
}
finally
{
if (host != null)
{
if (enumHandle != IntPtr.Zero)
{
host.CloseEnum(enumHandle);
}
Marshal.ReleaseComObject(host);
}
}
response = string.Empty;
}
public static void GetControlData(Int64 controlHandle, out string response)
{
//initialising COM
NativeMethods.CoInitializeEx(IntPtr.Zero, NativeMethods.COINIT.COINIT_MULTITHREADED);
mscoree.ICorRuntimeHost host = null;
try
{
host = (ICorRuntimeHost)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("CB2F6723-AB3A-11D2-9C40-00C04FA30A3E")));
}
catch (COMException comEx)
{
Trace.WriteLine($"COMException: {comEx.Message}, HRESULT: {comEx.ErrorCode}");
}
catch (Exception ex)
{
// Handle other exceptions
Trace.WriteLine($"Exception: {ex.Message}");
}
IntPtr enumHandle = IntPtr.Zero;
try
{
//now that we have ICorRuntimeHost object we can use it to enumerate the other domains
host.EnumDomains(out enumHandle);
object domain = null;
host.NextDomain(enumHandle, out domain);
while (domain != null)
{
//for each appdomain obtained
AppDomain appDomain = (AppDomain)domain;
//appDomain.BaseDirectory; - you might want to copy your dll
//in the appDomain.BaseDirectory cause otherwise it might not find
//the assembly
ObjectHandle handle = appDomain.CreateInstance(
typeof(CrossAppDomainRunner).Assembly.FullName,
typeof(CrossAppDomainRunner).FullName);
// Unwrap to get the actual object
var runnerProxy = handle.Unwrap();
// Use reflection to call the Execute method
MethodInfo executeMethod = runnerProxy.GetType().GetMethod("Execute", new Type[] { typeof(IntPtr) });
//pass parameters as new object[]
executeMethod.Invoke(runnerProxy, new object[] { new IntPtr(controlHandle) });
//go to next appdomain
host.NextDomain(enumHandle, out domain);
if (domain == null)
break;
}
}
finally
{
if (host != null)
{
if (enumHandle != IntPtr.Zero)
{
host.CloseEnum(enumHandle);
}
Marshal.ReleaseComObject(host);
}
}
response = string.Empty;
}
The example above injects the code in all AppDomains. Once you find out the AppDomain where the UI elements you want to indicate are located, you can enumerate all AppDomains, but inject code only in the necessary AppDomain.